$().ready(function(){
	$(".orderby-select").change(function(){
		 window.location.href=$(this).val();
	});	
})


function bindBoxUpload(bindId,tid){
    var button = $(bindId), interval;
    var fileType = "all",fileNum = "one"; 
    new AjaxUpload(button,{
        action: $("#newsurl").val()+"e/jat/add_tribepic_upload.php",
        name: 'Filedata',
		responseType:"json",
        onSubmit : function(file, ext){
            if(fileType == "pic"){
                if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)){
                } else {
                   // $('<li></li>').appendTo('#example .files').text('非图片类型文件，请重传');
				   alert('非图片类型文件，请重传');
                    return false;               
                }
            }                        
            button.val('文件上传中');            
            if(fileNum == 'one')
				
            interval = window.setInterval(function(){
                var text = button.text();
                if (text.length < 14){
                    button.val(text + '.');                    
                } else {
                    button.val('文件上传中');             
                }
            }, 200);
        },
		data:{"id":tid},
        onComplete: function(file, r){
			if(r.flag==1){
				popup_close();
				alert("成功建立部落！");
			}else if(r.msg){alert(r.msg);}else{	alert("系统错误，请与管理员联系");}                          
        }
    });
 
}

function setupTribe(){			
		popUpLoadUrl("建立部落",'add_tribe',{"act":"add_tribe"},function(){	
			if($(".list_box").length==0){return false;}
					LoadProvice();						
					setSubmitOk();
				});
	
}
function setSubmitOk(){
					$('.tribe_tags>span>input').click(function(){
						window.tags=[];
						$('.tribe_tags>span>input').each(function(){
							if($(this).attr("checked")){
								window.tags.push($(this).val());
							}
						})
							$("#tags").val(window.tags.toString())						
						});
		 $(".ok_submit").click(function(){
							var title=$("#tribe_title").val();
							var content=$("#content").val();
							var type=$("#tribe_type").val();
							var p=$("#slt_province").val();
							var c=$("#slt_city").val();
							var all_c=$('#all_city').attr("checked");
							var tags=$("#tags").val();
							var pms='';
							$("input[name=permission]:radio").each(function(){								
								if($(this).attr("checked")){
									 pms=$(this).attr("value");
								}
							})							
							if(title.length<5){
								alert("标题不能少于5个字");
								$("#tribe_title").trigger('focus');
								return false;
							}
							if(content.length<20){
								alert("内容不能少于20个字");
								$("#content").trigger('focus');
								return false;
							}
							if($("#tribe_type").val()==0){
								alert("请选择圈子类型");
								$("#tribe_type").trigger('focus');
								return false;
							}
							if($("#all_city").attr("checked")==false  && ($("#slt_province").val()=='' || $("#slt_city").val()=='')){
								alert('请选择地区')
								return false;
							}
							$.ajax({type:"POST",
					dataType:"json",data:{"dataFromType":"ajax","act":"set_reg_status",
							"classid":$("#classid").val(),
							"enews":"MAddInfo",
							"enews":"MAddInfo",
							"title":(title),
							"content":(content),
							"type":type,
							"province":p,
							"city":c,
							"tags":tags,
							"permission":pms
						},
					url:($("#newsurl").val())+"e/DoInfo/ecms.php",success:function(r){
					if(r.flag==1){
						popUpLoadUrl("部落图片",'add_tribe_pic',{"act":"add_tribe_pic","&tribeid":r.tribe_id},function(){
							bindBoxUpload(".select_pic",r.tribe_id);
							
						});
						return false;
					}else if(r.msg){alert(r.msg);}else{	alert("系统错误，请与管理员联系");}}});
						});
}